package com.kezesong.leasing.service.impl;

import com.kezesong.leasing.entity.GoodsColorEntity;
import com.kezesong.leasing.entity.GoodsRAMEntity;
import com.kezesong.leasing.mapper.GoodsRAMMapper;
import com.kezesong.leasing.service.GoodsRamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class GoodsRamServiceImpl implements GoodsRamService {

    @Autowired
    private GoodsRAMMapper goodsRAMMapper;

    @Override
    public List<GoodsRAMEntity> getGoodsRAMList() {
        return goodsRAMMapper.selectAll();
    }

    @Override
    public List<GoodsRAMEntity> getGoodsRAMList(int goodsId) {
        Example example = new Example(GoodsColorEntity.class);
        example.createCriteria().andEqualTo("goodsId",goodsId);
        List<GoodsRAMEntity> goodsRAMEntities = goodsRAMMapper.selectByExample(example);
        return goodsRAMEntities;
    }

    @Override
    public int addGoodsRAM(GoodsRAMEntity goodsRAMEntity) {
        goodsRAMEntity.setCreatedTime(new Date());
        int rows = goodsRAMMapper.insert(goodsRAMEntity);
        return rows;
    }

    @Override
    public int deleteGoodsRAM(int goodsRAMId) {
        int rows = goodsRAMMapper.deleteByPrimaryKey(goodsRAMId);
        return rows;
    }

    @Override
    public int modifyGoodsRAM(GoodsRAMEntity goodsRAMEntity) {
        goodsRAMEntity.setCreatedTime(new Date());
        int rows = goodsRAMMapper.updateByPrimaryKey(goodsRAMEntity);
        return rows;
    }
}
